<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<!--  JQUERY CSS -->
<link rel="stylesheet"
	href="script/jquery/themes/dark-hive/jquery-ui.css" />


<!--  Marelab CSS -->
<link rel="stylesheet" href="css/marelab.css" />

<style>
.ui-progressbar .ui-progressbar-value {
	background-image: url(images/pbar-ani.gif);
}
</style>


<link href="favicon.ico" rel="shortcut icon"
	type="image/vnd.microsoft.icon" />

<style type="text/css">
.PluginButton {
	background-color: #114a69;
	-moz-border-radius: 9px;
	-webkit-border-radius: 9px;
	border-radius: 9px;
	display: inline-block;
	color: #ffffff;
	font-family: Arial;
	font-size: 15px;
	font-weight: bold;
	padding: 5px 10px;
	width: 120px;
	text-decoration: none;
}
/* This imageless css button was generated by CSSButtonGenerator.com */
</style>

<!--  JQUERY INCLUDE -->
<script src="script/jquery/jquery-1.8.2.js"></script>
<script src="script/jquery/ui/jquery-ui.js"></script>

<!-- Language includes -->
<script src="script/marelab/marelab_lan_EN.js"></script>



<script>

	
	var content_container;
	var content_plugin;
	var content_main_menu;
	
	// mcu plugin config object
	
	var PluginLogicObjectList = [];
		
	
	$(function() {
    	$("#BUTTONLOG").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: true } );
        $("#BUTTON_SCAN_PLUGIN").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: true } );
        $("#BUTTON").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: false } );
        $("#BUTTON_SCAN_MBD").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: true } );
        $("#BUTTONLOG").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: true } );
        $("#SAVEPORT").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: true } );
        $("#PORTSCAN").button( {icons: {primary: "ui-icon-refresh ui-icon-refresh-1-n"}, text: true } );
        $("#accordion" ).accordion({ heightStyle: "fill" });
    });
	
	
	function loadjscssfile(filename, filetype) {
		if (filetype == "js") { //if filename is a external JavaScript file
			var fileref = document.createElement('script')
			fileref.setAttribute("type", "text/javascript")
			fileref.setAttribute("src", filename)
		} else if (filetype == "css") { //if filename is an external CSS file
			var fileref = document.createElement("link")
			fileref.setAttribute("rel", "stylesheet")
			fileref.setAttribute("type", "text/css")
			fileref.setAttribute("href", filename)
		}
		if (typeof fileref != "undefined")
			document.getElementsByTagName("head")[0].appendChild(fileref)
	}
	
	// Gets executed first call of document
	$(document).ready(function() {
		// load all Plugin Scripts
		LoadPluginScripts();
    	// Get Deamon Info	
		mCU_PORTSCAN();
		mcu_BUSRESTORE();
		
		// Build Logic & Adapter Plugin Table
		MarelabVersion();
		
		
		CreatePluginMenu();
		
		generateLogicPlugin();
	});
	
	$(document).ready(function(){
	    
		var p=0;
	    
		// SAVES the CONTENT OF THE FIRST PAGE
		content_container = $("#tabs-1").html();
		content_main_menu = $("#main_menu").html();
		
		$("#myDialog").dialog({
	        height: 100,
	        width:500,
	        autoOpen:true
	    });
	    
	    $("#myProgressBar").progressbar({
	    	value:0,
	    width:500
	    	
	    });
	        var timer = setInterval(function(){
	            //This animates the bar
	            $("#myProgressBar .ui-progressbar-value").animate({width: p+"%"}, 500);
	            //This does static sets of the value
	            //$("#myProgressBar").progressbar("option","value",p);
	            p = p +3;
	            if(p>100){
	                $("#myProgressBar .ui-progressbar-value").animate({width: "100%"}, 500);
	                //$("#myProgressBar").progressbar("option","value",100);
	                clearInterval(timer);
	            }
	    },500);
	});
	
	
	

	
	
	// Add a mBD Device Row
	// <div id="listOfPlugins">
	function addPluginList_HTML(name,version){
		var html = '<table width="400px" border="0" cellspacing="4" cellpadding = "4">';
		html = html + '	<tr >';
		html = html + '		<th width="100px align="left" id="MDB-mCU-content1">';
		html = html + version;
		html = html + '		</th>';
		html = html + '		<th align="left" id="MDB-mCU-content2">';
		html = html + '			' + name ;
		html = html + '		</th>';
		html = html + '	</tr> ';
		html = html + '</table>';
		return html;
	}
	
	// RESTORE THE SETTINGS THE PORT
	function mcu_BUSRESTORE(){
		var plugin_info;
	    jsonRET = getMarelabData('COMMAND=mcu_BUSRESTORE');
	    //alert(jsonRET.PARAMETER.BUS[0].BUS.BAUD);
	    //$("#mCU_BAUD").selectOptions();
	    
	    // REWORK OF HARDWARE PLUGS
	    //$("#mCU_PORT").val( jsonRET.PARAMETER.BUS[0].BUS.PORT ).prop('selected',true);
	    //$("#mCU_BAUD").val( jsonRET.PARAMETER.BUS[0].BUS.BAUD ).prop('selected',true);
	    
	    // Restore the mBD on the Bus the list is done by the readed devices in the confighm
	    //for (x in jsonRET.PARAMETER.MBD) {
	    //	adress = jsonRET.PARAMETER.MBD[x].MBD.ADRESSE;
	    //	major  = jsonRET.PARAMETER.MBD[x].MBD.VERSIOMAJOR;
	    //	minjor = jsonRET.PARAMETER.MBD[x].MBD.VERSIOMINOR;
	    //	name   = jsonRET.PARAMETER.MBD[x].MBD.NAME.toString();
	    //	uuid   = jsonRET.PARAMETER.MBD[x].MBD.UUID.toString();	
	    //	$("table#MDB-TABLE-LIST").append(addMBD_HTML(x,adress,major,minjor,name,uuid));
		//}
	}
	
	function MarelabVersion(){
		var plugin_info;
	    jsonRET = getMarelabData('COMMAND=mcu_VERSION');
		$("p#deamonVersion").html("Version:" + jsonRET.PARAMETER);
		$("spam#deamonVersion").html(jsonRET.PARAMETER);
	}
	
	
	
	function getMarelabData(what2Get) {
		var dataret;
		$.ajax({
			type : "POST",
			//url: 'cgi.php',
			url : 'cgi/marelab-cgi',
			data : what2Get,
			async : false,
			beforeSend : function(x) {
				if (x && x.overrideMimeType) {
					x.overrideMimeType("application/j-son;charset=UTF-8");
				}
			},
			dataType : "json",
			success : function(data) {
				dataret = data;
				if (data.ERROR) {
					// ERROR HAS HAPPEND 
					alert(data.ERROR);
				}
			}
		});
		return dataret;
	}

	// Load javascripts that belongs to the plugins that are installed 
	function LoadPluginScripts() {
		// get the list of javascript files form the plugin regestry
		// the names are just generated by the pluginname +".js" 
		var what2Get = getMarelabData('COMMAND=PLUGIN_JAVASCRIPTFILES');
		//getMarelabData(what2Get);
		for (x in what2Get.PARAMETER) {
			
			scriptname = what2Get.PARAMETER[x].PLUGINNAME + ".css";
			scriptname = "/plugins/" + scriptname;
			loadjscssfile(scriptname, "css"); //dynamically load and add this .js file
			
			scriptname = what2Get.PARAMETER[x].PLUGINNAME + ".js";
			scriptname = "/plugins/" + scriptname;
			loadjscssfile(scriptname, "js"); //dynamically load and add this .js file
			
		}
	}
	
	// Returns a list of Ports found on the mCU
	// {"COMMAND":"mcu_PORTSCAN","PARAMETER":[{"port":"/dev/ttyACM0"},{"port":"/dev/ttyS1"},{"port":"/dev/ttyS0"}]}
	function mCU_PORTSCAN() {
		jsonRET = getMarelabData('COMMAND=mcu_PORTSCAN');
		$("select#mCU_PORT option").remove();
		
		for (var i=0 ; i< jsonRET.PARAMETER.length; i++){
			$("select#mCU_PORT").append("<option>"+jsonRET.PARAMETER[i].port+"</option>");	
		}
	            
	}
	
	function mCU_CONFIGSAVE() {
		sC = new Object();
	    sC.COMMAND   = 'mcu_BUSSAVE';
	    sC.PORT = $("#mCU_PORT option:selected").text();
	    sC.BAUD = $("#mCU_BAUD option:selected").text();
	   	sC.DATABITS = '8';
	    sC.PARITY='N';
	    sC.STOPBITS = '1';
		para='test","PORT":"'+sC.PORT+'","BAUD":"'+sC.BAUD+'","DATABITS":"'+sC.DATABITS+'","PARITY":"'+sC.PARITY+'","STOPBITS":"'+sC.STOPBITS;

		jsonRET = getMarelabData('COMMAND=mcu_BUSSAVE&PARAMETER='+para);
	}
	
	// Add a mBD Device Row
	function addMBD_HTML(id,adress,major,minjor,name,uuid){
		var html = '<tr id="MBDROW'+id+'">';
		html = html + '<th width="70px" scope="col" align="left">';	
		html = html + '	<imgage ><img src="img/mbd.png" onClick="" ></imgage>';
		html = html + '</th>';
		html = html + '<th scope="col" align="left"> ';
		html = html + '	<table width="400px" border="0" cellspacing="4" cellpadding = "4">';
		html = html + '	<tr >';
		html = html + '		<th width="100px align="left" id="MDB-mCU-content1">';
		html = html + 			mlang["mBDBname"]+':';
		html = html + '		</th>';
		html = html + '		<th align="left" id="MDB-mCU-content2">';
		html = html + '			' + name +' UUID:' +uuid+' ';
		html = html + '		</th>';
		html = html + '	</tr> ';
		html = html + '	<tr>';
		html = html + '		<th width="100px align="left" id="MDB-mCU-content1">';
		html = html + mlang["Firmware"];
		html = html + '		</th>';
		html = html + '		<th align="left" id="MDB-mCU-content2">';
		version = major + "." + minjor;
		html = html + '			'+ version +' ';
		html = html + '		</th>';
		html = html + '	</tr>';
		html = html + '	<tr>';
		html = html + '		<th width="100px align="left" id="MDB-mCU-content1">';
		html = html + 			mlang["mBDAdress"]+':';
		html = html + '		</th>';
		html = html + '		<th align="left" id="MDB-mCU-content2">';
		html = html + '			' + adress+' ';
		html = html + '		</th>';
		html = html + '	</tr> ';
		html = html + '</table>';
		html = html + '</th>';
		html = html + '</tr>';
		return html;
	}
	
	

	
	
	
	// Scannt the BUS for mBD Devices
	function mcu_BUSSCAN(){
		// First del all devices on the DOM Tree
		$("[id^=MBDROW]").remove();
		
	    jsonRET = getMarelabData('COMMAND=mcu_BUSSCAN');
	    
	    for (x in jsonRET.PARAMETER) {
	    	adress = jsonRET.PARAMETER[x][0].ADRESS;
	    	major  = jsonRET.PARAMETER[x][1].MAJOR;
	    	minjor = jsonRET.PARAMETER[x][2].MINJOR;
	    	name   = jsonRET.PARAMETER[x][3].NAME;
	    	uuid   = jsonRET.PARAMETER[x][4].UUID;	
	    	$("table#MDB-TABLE-LIST").append(addMBD_HTML(x,adress,major,minjor,name,uuid));
		}
	    //$("#accordion" ).accordion({ heightStyle: "fill" });
	    //alert(jsonRET.PARAMETER[0][0].ADRESS);	
		
	}
	

	
	function doSomethingWithData(data) {
		content_plugin = data;
	} 
	
	// Creates the Menu with all plugins
	// Creates the Plugin List
	function CreatePluginMenu(){
		json = GET_PLUGININFO();
		
		// Logic Plugins
		for (var i=0 ; i< jsonRET.PARAMETER.length; i++){
					// Menu Entry
					$("#MENU_FOR_PLUGINS").append(PluginMenuEntry(jsonRET.PARAMETER[i].PLUGINNAME));
					// List of Logic Plugs
					$("#listOfPlugins").append(addPluginList_HTML(jsonRET.PARAMETER[i].PLUGINNAME,jsonRET.PARAMETER[i].PLUGINVERSION));
		}
		
		// Adapter Plugins
		jsonAdapterPlugs = getMarelabData('COMMAND=GET_ADAPTERINFO');
		
		for (var i=0 ; i< jsonAdapterPlugs.PARAMETER.length; i++){
			// List of Adapter Plugs
			$("#listOfPlugins").append(addPluginList_HTML(jsonAdapterPlugs.PARAMETER[i].PLUGINNAME,jsonAdapterPlugs.PARAMETER[i].PLUGINVERSION));
		}
	}
		
	function PluginMenuEntry(name){
		return '<p class="PluginButton" id="'+name+'" onClick="MenuClicked(\''+name+'\');">'+ name +'</p>';
	}
	
	function SetupMenu(){
		$("#tabs-1").empty();
		$("#tabs-1").append(content_container);
		// Appand again the main menu
		$("#main_menu").empty();
		$("#main_menu").append(content_main_menu);
		generateLogicPlugin();
	}
	
	
	function MenuClicked(name){
		var content;
		// Copy the main menu to var
		//content_main_menu = $("#main_menu").html();
		$("#main_menu").empty();
		
		file2load = '/plugins/'+ name + '.html';
		var jqxhr = $.get(file2load, doSomethingWithData);
		jqxhr.complete(function(){ 
		//content_container = $("#tabs-1").html();
		$("#tabs-1").empty();
		$("#tabs-1").append(content_plugin);
		eval(name +"_Init();");
		//LedDimmer_Init();
		
		});		
		
	}
	
	// Adds the logmessages to the log div
	function refreshLogText(){
		$("p#loginfo").empty();
		jsonRET = getMarelabData('COMMAND=deamon_LOG');
	    $("p#loginfo").append(jsonRET.PARAMETER);
	}
	
	// Get LOG Messages from the marelab deamon
	function deamon_LOG(){		
		refreshLogText();
	    //logbut = '<button id="BUTTON" onclick="deamon_LOG()"></button>';	    
	    
	    $( "#dialoglog").dialog({ height: 400 , width: 500 , buttons: { close: function() { $( this ).dialog( "close" ); },
	    	refresh: function() { refreshLogText(); } }});
	   // $("#dialoglog").dialog({ height: 400 , width: 500 });
	}
	
	
	function changeText(name){
		document.getElementById(name).innerHTML = mlang[name];
	}
	
	
	
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///Plugin Logic & Adapter handling                                                                         //
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function GET_PLUGININFO(){
		jsonRET = getMarelabData('COMMAND=GET_PLUGININFO');
		
		// Adding PluginInfos to internal Object struct
		pluginCount = jsonRET.PARAMETER.length;
		for (i=0; i<pluginCount;i++)
		{
			var PluginLogicObject = new Object();
			PluginLogicObject.Name = jsonRET.PARAMETER[i].PLUGINNAME;
			PluginLogicObject.Version = jsonRET.PARAMETER[i].PLUGINVERSION;
			PluginLogicObject.Adapter = "";
			PluginLogicObject.AdapterVersion="";
			PluginLogicObjectList[i] = PluginLogicObject;
		}
		return jsonRET;
	}
	
	function SaveLogicAdapterPluginConfig()
	{
		
		var AdpaterSelected;
		pluginCount = PluginLogicObjectList.length;
		for (i=0; i<pluginCount;i++)
		{
			PluginLogicObject = PluginLogicObjectList[i];
			whichAdapter = "AdapterList"+i;
			PluginLogicObject.Adapter = $("#"+whichAdapter+" option:selected").text();
		}
		//para='test","PORT":"'+sC.PORT+'","BAUD":"'+sC.BAUD+'","DATABITS":"'+sC.DATABITS+'","PARITY":"'+sC.PARITY+'","STOPBITS":"'+sC.STOPBITS;
		//alert (JSON.stringify(PluginLogicObjectList));
		jsonRET = getMarelabData('COMMAND=mcu_NUCLEUS_CONFIGSAVE&PARAMETER='+JSON.stringify(PluginLogicObjectList));	
	}
	
	// Get the HardwareAdapterConfig Dialog for a Logic Plugin
	function GetAdapterPluginConfigHTML(logicPluginName){
		// Removing exosting Adapter Config Html Code to the Config Adapter Dialog
		$("#AdapterConfigContent").empty();
		//'COMMAND=READ_CONFIG&PARAMETER="PLUGIN":"LedDimmer"'
		jsonRET = getMarelabData('COMMAND=ADAPTER_GET_CONFIG_HTML&PARAMETER="PLUGIN":"'+logicPluginName+ '"');
		// Adding the returned Adapter Config Html Code to the Config Adapter Dialog
		$("#AdapterConfigContent").append(jsonRET.HTML);
		$('#AdapterConfig' ).dialog();
  	}
	
	// Get the HardwareAdapterConfig as insert for table
	function GetAdapterPluginConfigHtmlTable(logicPluginName){
		//'COMMAND=READ_CONFIG&PARAMETER="PLUGIN":"LedDimmer"'
		jsonRET = getMarelabData('COMMAND=ADAPTER_GET_CONFIG_HTML&PARAMETER="PLUGIN":"'+logicPluginName+ '"');
		return jsonRET.HTML;
	
  	}
	
	function ReplaceAdapter(adapterName){
		alert(adapterName);
		//var replaceSpan = "span#Logic2Adapter"+logicplugin;
		//alert(replaceSpan);
		//$('span#Logic2Adapter1').html(adapterName);
	}
	
	function AdapterDialog(pluginhardware){
		//$('#AdapterDialog' ).dialog();
		//alert(pluginhardware[0].ADAPTER_NAME);
		//$('p#AdapterSelection').html.clear();
		var plugins = GET_PLUGININFO();
		var htmlout ="";
		var AdapterName="";
		adapterCount = plugins.PARAMETER[pluginhardware].PLUGINHARDWARE.length;
		for (i=0; i<adapterCount;i++)
		{
			AdapterName = plugins.PARAMETER[pluginhardware].PLUGINHARDWARE[i].ADAPTER_NAME
			htmlout = htmlout + "<input type='button' name='SetAdapter' value='Select' onclick='ReplaceAdapter("+AdapterName+");'> "+ plugins.PARAMETER[pluginhardware].PLUGINHARDWARE[i].ADAPTER_NAME + " version:" +plugins.PARAMETER[pluginhardware].PLUGINHARDWARE[i].ADAPTER_VERSION+"<br>";
		}
		
		$('p#AdapterSelection').html(htmlout);
		$('#AdapterDialog' ).dialog();
		
	}
	
	function generateLogicPlugin(){
		var pluginTable, AdapterSelect;
		AdapterSelect = "";
		plugintable = pluginTable + '<table width="400" border="0" cellspacing="0" cellpadding="0">';
		
		// MCU Version
		
		jsonRET = getMarelabData('COMMAND=mcu_VERSION');
		$("p#deamonVersion").html("Version:" + jsonRET.PARAMETER);
		$("spam#deamonVersion").html(jsonRET.PARAMETER);
		
		
		pluginTable = pluginTable + '  <tr>';
		pluginTable = pluginTable + '    <td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">';
		pluginTable = pluginTable + '      <tr>';
		pluginTable = pluginTable + '        <td width="75" rowspan="2" bgcolor="#003366"><img src="img/marelab-logo-transparent.png" width="75" height="63" alt="ss" /></td>';
		pluginTable = pluginTable + '        <td colspan="3" bgcolor="#006699"><p>marelab nucleus mcu <br/>';
		pluginTable = pluginTable + '          Version: '+jsonRET.PARAMETER+' </p>';
		pluginTable = pluginTable + '       </td>';
		pluginTable = pluginTable + '      </tr>';
		pluginTable = pluginTable + '      <tr>';
		pluginTable = pluginTable + '        <td width="57" align="center" bgcolor="#006699"><input type="image" onclick="generateLogicPlugin();" src="img/REFRESH.png" width="32" height="32" alt="save config" /></td>';
		pluginTable = pluginTable + '        <td width="65" align="center" bgcolor="#006699"><img src="img/setup.png" alt="sd" width="32" height="32" /></td>';
		pluginTable = pluginTable + '        <td width="95" align="center" bgcolor="#006699"><input type="image" onclick="SaveLogicAdapterPluginConfig();" src="img/savef.png" width="32" height="32" alt="save config" /></td>';
		pluginTable = pluginTable + '      </tr>';
		pluginTable = pluginTable + '   </table></td>';
		pluginTable = pluginTable + '  </tr>';
		
		
		
		// Logic Plugins
		plugins = GET_PLUGININFO();
		pluginCount = plugins.PARAMETER.length
		for (i=0; i<pluginCount;i++)
		{
			AdapterSelect = "";
			pluginTable = pluginTable + '<tr>';
			pluginTable = pluginTable + '    <td valign="top"><img src="img/VERTICAL.png"  width="32" height="32" alt="aa"/></td>';
			pluginTable = pluginTable + '    <td>&nbsp;</td>';
			pluginTable = pluginTable + '</tr>';
			pluginTable = pluginTable + '<tr>';
			
			if (i<(pluginCount-1)){
				pluginTable = pluginTable + '<td valign="top"><img src="img/MIDDLE.png" width="32" height="32" alt="aa" /><br/>';
				pluginTable = pluginTable + '	<img src="img/VERTICAL.png"  width="32" height="32" alt="aa"/><br /> ';     
				pluginTable = pluginTable + '	<img src="img/VERTICAL.png"  width="32" height="32" alt="aa"/>';
				pluginTable = pluginTable + ' </td>';
				pluginTable = pluginTable + '<td>';
			}else{
				pluginTable = pluginTable + '<td valign="top"><img src="img/LAST.png" width="32" height="32" alt="aa" /><br/>';
				
				pluginTable = pluginTable + ' </td>';
				pluginTable = pluginTable + '<td>';
			}
			
		
			pluginTable = pluginTable + ' <table width="100%" border="0" cellpadding="4" cellspacing="4">';
			pluginTable = pluginTable + '  <tr>';
			pluginTable = pluginTable + '    <td width="87" rowspan="2" align="center" bgcolor="#003366"><input type="image" onclick="led_SAVECURVE();" src="img/'+plugins.PARAMETER[i].PLUGINNAME+'.png" width="32" height="32" alt="save config" /></td>';
			pluginTable = pluginTable + '    <td bgcolor="#006699">'+plugins.PARAMETER[i].PLUGINNAME+'<br />';
			pluginTable = pluginTable + 'Version: '+plugins.PARAMETER[i].PLUGINVERSION+'</td>';
			pluginTable = pluginTable + '    <td align="right" bgcolor="#006699"><input type="image" onclick="GetAdapterPluginConfigHTML(\''+plugins.PARAMETER[i].PLUGINNAME+'\');" src="img/setup.png" width="32" height="32" alt="config_hardwareAdapter" /></td>';
			pluginTable = pluginTable + '    <td align="right" bgcolor="#006699"><input type="image" onclick="SaveLogicAdapterPluginConfig();" src="img/savef.png" width="32" height="32" alt="save config" /></td>';
			pluginTable = pluginTable + '  </tr>';
			pluginTable = pluginTable + '  <tr>';
			logic2adapterName = 'Logic2Adapter'+i; 
			logic2adapterList = 'AdapterList'+i; 
			AdapterSelect = AdapterSelect + '<select name="AdapterSelect" id="'+logic2adapterList+'">';
			adapterCount = plugins.PARAMETER[i].PLUGINHARDWARE.length;
			for (ii=0; ii<adapterCount;ii++)
			{
				AdapterName = plugins.PARAMETER[i].PLUGINHARDWARE[ii].ADAPTER_NAME;
				AdapterNameSelected = plugins.PARAMETER[i].SELECTEDADAPTER;
				
				if (AdapterName === AdapterNameSelected ){
					AdapterSelect = AdapterSelect +  '<option value="'+AdapterName+'" selected>'+AdapterName+'</option>';
				}
				else{
					AdapterSelect = AdapterSelect +  '<option value="'+AdapterName+'">'+AdapterName+'</option>';
				}
			}
			AdapterSelect = AdapterSelect + '</select>';
			
			
			pluginTable = pluginTable + '    <td align="left" bgcolor="#006699">Adapter: <span id="'+logic2adapterName+'">'+AdapterSelect+'</span></td>';
			pluginTable = pluginTable + '    <td width="30" align="center" bgcolor="#006699"><input type="image" onclick="AdapterDialog('+i+');" src="img/hardware.png" width="32" height="32" alt="sd" /></td>';
			pluginTable = pluginTable + '    <td width="34" align="center" bgcolor="#006699"><img src="img/onoff.png" width="32" height="32" alt="as" /></td>';
			
			
			//<!-- ADDING HARDWARE/CHIPS CONFIG 
			//pluginTable = pluginTable + '    <td align="right" bgcolor="#006699">'+GetAdapterPluginConfigHTML(plugins.PARAMETER[i].PLUGINNAME)+'</td>';
			
			//-->
			
			pluginTable = pluginTable + '   </tr>';
			pluginTable = pluginTable + ' </table>';
			pluginTable = pluginTable + '  </td>';
			pluginTable = pluginTable + '   </tr>';
		}
		
		

		  
		pluginTable = pluginTable + '</table>';
		
		$("#pluginadaperlist").html(pluginTable);
		
	}
	
	//function HtmlInjection(id_target,htmlinjection)
	function HtmlInjection(ID_SELECT,textinsert)
	{
		// Get the option selected 
		var selectName = $('#CHIPSET_SELECT').find(":selected").text();
		
		$("#"+ID_SELECT).html("<td>"+selectName+"</td>");
	}
	
	
	function ConnectorDialog(titel,content){
		//var plugins = GET_PLUGININFO();
		var htmlout = content;
		var AdapterName="";
		//adapterCount = plugins.PARAMETER[pluginhardware].PLUGINHARDWARE.length;
		//for (i=0; i<adapterCount;i++)
		//{
		//	AdapterName = plugins.PARAMETER[pluginhardware].PLUGINHARDWARE[i].ADAPTER_NAME
		//	htmlout = htmlout + "<input type='button' name='SetAdapter' value='Select' onclick='ReplaceAdapter("+AdapterName+");'> "+ plugins.PARAMETER[pluginhardware].PLUGINHARDWARE[i].ADAPTER_NAME + " version:" +plugins.PARAMETER[pluginhardware].PLUGINHARDWARE[i].ADAPTER_VERSION+"<br>";
		//}
		
		$('p#ConnectorConfigContent').html(htmlout);
		$('#ConnectorConfig' ).dialog();
		
	}
	
</script>



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>
<title>marelab reef control</title>
<body>

	<div id="titel_setup">
		<div id="TOOLBAR-TITEL">
			<img src="img/logo2-marelab.png">
		</div>
		<div id="TOOLBAR">
			<!--  <button id="test" onClick="LedDimmer();">TEST</button>-->
			<!--<span id="main_menu">
				<button id="SAVEPORT" onclick="mCU_CONFIGSAVE()">save</button>
			</span>-->
			<input type="image" onclick="deamon_LOG();" src="img/loginfo.png" width="32" height="32" alt="save config" />
			<!-- <button id="BUTTONLOG" onclick="deamon_LOG()">log</button> -->
		</div>
	</div>
	<div id="container-content">
		<div id="tabs">
			<div id="LINKS">
				<!-- ************************************** -->
				<!-- FILL PLUGIN MENUS -->
				<!-- ************************************** -->
				<div id="PLUGIN_MENU"></div>
				<div id="MENU_FOR_PLUGINS"></div>
				<p class="PluginButton" onClick="SetupMenu();">Setup</p>
				
				<!-- ************************************** -->
				<!-- OS INFO LINUX                          -->
				<!-- ************************************** -->
				<p class="PluginButton" onClick="">OS Info</p>
				
				<!-- ************************************** -->
				<!-- FILL PLUGIN MENUS -->
				<!-- ************************************** -->			
			</div>
			
	
			
			<div id="tabs-1">
				<div id="RECHTS">
					<!-- **************   SETUP CONTENT ********************* -->
					<!-- 
						<div id="titel_setup_content">
						<div class="TOOLBAR-TITEL" id="TOOLBAR-TITEL-PORTSETTING"><script>changeText('TOOLBAR-TITEL-PORTSETTING');</script></div>
						<div id="TOOLBAR">
							<button id="PORTSCAN" onclick="mCU_PORTSCAN()"><script>changeText('PORTSCAN');</script></button>
						</div>
					</div>
					<div id="container">
						<div id="LINKS">
							
						</div>
						<div id="RECHTS" class=".ui-accordion-header">
						<span id="portDescription">
						<script>changeText('portDescription');</script>
							
							</span>
							<br></br>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<th scope="col" align="left" id="PortInputFieldName"><script>changeText('PortInputFieldName');</script></th>
									<th scope="col" align="left"><select id="mCU_PORT"
										size="1"><option>*UNDEFINED*</option></select></th>
								</tr>
								<tr>
									<th scope="col" align="left" id="PortBaudFieldName"><script>changeText('PortBaudFieldName');</script></th>
									<th scope="col" align="left"><select id="mCU_BAUD"
										size="1">
											<option>2400</option>
											<option>4800</option>
											<option>9600</option>
											<option>19200</option>
											<option>38400</option>
											<option>57600</option>
											<option>115200</option>
									</select></th>
								</tr>
							</table>

							</th>
							</tr>

							</table>
						</div>
						<br></br>
					</div>
					-->
					<div id="titel_setup_content">
						<div class="TOOLBAR-TITEL" id="titelmBDDeviceList">
							<script>changeText('titelmBDDeviceList');</script>
						</div>
						<div id="TOOLBAR">
							<!-- 
							OLD MODBUS 
							<button id="BUTTON_SCAN_MBD" onclick="mcu_BUSSCAN()">
								<script>changeText('BUTTON_SCAN_MBD');</script>
							</button>
							<!-- <div id='myProgressBar'></div> -->
							 
						</div>
					</div>
					<div id="container">
						<!-- START OF mBD SETUP & SCAN -->
						<!-- ************************* -->
						<div id="LINKS">
							<!-- FILL -->
						</div>
						<div id="RECHTS" class=".ui-accordion-header">

							<span id="pluginadaperlist"></span>

						</div>
					</div>

					<div id="titel_setup_content">
						<div class="TOOLBAR-TITEL" id="toolbarTitelPluginsInstalled">
							<script>changeText('toolbarTitelPluginsInstalled');</script>
						</div>
						<div id="TOOLBAR">
							<input type="image" onclick="GET_PLUGININFO();" src="img/REFRESH.png" width="32" height="32" alt="save config" />
							<!-- <button id="BUTTON_SCAN_PLUGIN" onclick="GET_PLUGININFO()">refresh</button> -->
						</div>
					</div>
					<div id="container">
						<!-- START OF PLUGIN SCAN -->
						<!-- ************************* -->
						<div id="LINKS">
							<!-- FILL -->
						</div>
						<div id="RECHTS">
							<div id="listOfPlugins">
								<!-- LIST OF PLUGINS -->
								<!-- ************************* -->
							</div>
						</div>
					</div>
					<!-- **************   END SETUP CONTENT ********************* -->

				</div>
				<!-- </div> CONTAINER-RIGHT -->
			</div>
		</div>
	</div>
	<div id="footer">
		<div id="TOOLBAR-TITEL">
			<p id="deamonVersion">Version:</p>
			<a href="http://www.marelab.org">open source reef control
				www.marelab.org</a>
		</div>
		<div id="TOOLBAR"></div>
	</div>

	<div id="dialoglog" title="marelab deamon Log">
		<p id="loginfo"></p>
	</div>
	<!-- Dialog for the Adapter Seclection -->
	<div id="AdapterDialog" style="display: none" title="Adapter Selction">
		<p id="AdapterSelection"></p>
	</div>
	
	<!-- Dialog for the Adapter Configuration -->
	<div id="AdapterConfig" style="display: none" title="Adapter Configuration">
		<p id="AdapterConfigContent"></p>
	</div>
	
	
	<!-- 
		Dialog for the Connector Configuration 
		This is a universal Dialog for all logic 
		Plugins. 
	-->
	
	<div id="ConnectorConfig" style="display: none" title="Connector Configuration">
		<p id="ConnectorConfigContent"></p>
	</div>
	

</body>
</html>

